/**
 * filters/num-percent
 *
 * 百分比显示
 */

define(['vue'], function(Vue) {
    return Vue.filter('numPercent', {
        read: function(num, fixedLen) {
            if(fixedLen === undefined) {
                fixedLen = -1;
            }

            num *= 100;

            if(fixedLen < 0) {
                num = Math.round(num);
            }
            else {
                num = num.toFixed(fixedLen);
            }

            return num + '%';
        },
        write: function(num) {
            var val = parseFloat(num) || 0;

            return val / 100;
        }
    });
});
